#include "StdAfx.h"
#include "RegHandler.h"


RegHandler::RegHandler(void)
{
}


RegHandler::~RegHandler(void)
{
}
// success 0, can't find is -1
int RegHandler::OpenReg()
{
	int nRtn = ERROR_SUCCESS;
	nRtn = RegOpenKeyEx(ROOT_KEY, DATA_SETTING, 0, KEY_ALL_ACCESS, &m_hKey);
	RegCloseKey(m_hKey);
	return nRtn;
}
// struct today(time), week(7 types), month(31types), year(date,366it max)
// when key have value, the key exist or delete
int RegHandler::GetAllRecord(int nType)	// get values which match the key 
{
	return 0;
}
int RegHandler::AddRecord(int nType, LPCTSTR strKey, LPCTSTR strValue)
{
	return 0;
}
// end user click delete, check the null record
int RegHandler::DelRecord(int nType, LPCTSTR strKey, LPCTSTR strValue)
{
	return 0;
}
int RegHandler::CloseReg()
{
	return 0;
}
int RegHandler::ReadData(LPCTSTR strName, CString *strValue)
{
	int nRtn = ERROR_SUCCESS;	
	long dwSize=256;
	TCHAR szString[1024];
	nRtn = RegOpenKeyEx(ROOT_KEY, strName, 0, KEY_ALL_ACCESS, &m_hKey);
	if(nRtn==ERROR_SUCCESS)
	{
		nRtn=RegQueryValue(m_hKey,NULL,szString,&dwSize);
	}
	if(nRtn==ERROR_SUCCESS)
	{
		*strValue=szString;
	}
	RegCloseKey(m_hKey);
	return nRtn;
}

int RegHandler::ReadData(LPCTSTR strName, LPCTSTR strKey, CString *strValue)
{
	int nRtn = ERROR_SUCCESS;	
	DWORD dwSize=256;
	DWORD dwType = REG_SZ;
	TCHAR szString[1024];
	nRtn = RegOpenKeyEx(ROOT_KEY, strName, 0, KEY_ALL_ACCESS, &m_hKey);
	if(nRtn==ERROR_SUCCESS)
	{
		nRtn=RegQueryValueEx(m_hKey,strKey,0, &dwType, (BYTE *)szString,&dwSize);
	}
	if(nRtn==ERROR_SUCCESS)
	{
		*strValue=szString;
	}
	RegCloseKey(m_hKey);
	return nRtn;
}

int RegHandler::ReadData(LPCTSTR strName, LPCTSTR strKey, DWORD *strValue)
{
	int nRtn = ERROR_SUCCESS;	
	DWORD dwSize=256;
	DWORD dwType = REG_SZ;
	DWORD szString;
	nRtn = RegOpenKeyEx(ROOT_KEY, strName, 0, KEY_ALL_ACCESS, &m_hKey);
	if(nRtn==ERROR_SUCCESS)
	{
		nRtn=RegQueryValueEx(m_hKey,strKey,0, &dwType, (BYTE *)&szString,&dwSize);
	}
	if(nRtn==ERROR_SUCCESS)
	{
		*strValue=szString;
	}
	RegCloseKey(m_hKey);
	return nRtn;
}
//end of files
